$(function() {
	layui.use([ 'form', 'jquery' ], function() {
		var form = layui.form;
		var $ = layui.jquery;
		form.verify({
			username : function(value) {
				if (value.length <= 0) {
					return '用户名不能为空';
				}
			},
			password : function(value) {
				if (value.length <= 0) {
					return '密码不能为空';
				}
			}
		})
		form.on('submit(loginForm)', function() {
			$.ajax({
				url : getContextPath() + '/doLogin',
				type : 'post',
				dataType : 'text',
				data : {
					username : $('#username').val(),
					password : $('#password').val(),
					rememberme : $('#rememberme').val()
				},
				success : function(result) {
					var restjson = JSON.parse(result)
					if (restjson.isSuccess) {
						layer.msg(restjson.msg, {
							icon : 1,
							time : 1000
						}, function() {
							location.href = getContextPath() + "/";
						});
					} else {
						layer.msg(restjson.msg, {
							icon : 2,
							time : 1000
						}, function() {
						});
						return false;
					}
				}
			})
			return false;
		});
	})
	if (window != top) {
		top.location.href = location.href;
	}
});